<template>
  <!-- 驳回原因 -->
  <el-dialog
    v-el-drag-dialog
    title="驳回原因"
    :visible.sync="visible"
    width="50%"
    append-to-body
    @close="reset"
  >
    <el-form ref="dataForm" label-position="left" label-width="90px">
      <el-form-item label="驳回原因:">
        <el-input v-model.trim="rejectRemark" type="textarea" :rows="3" maxlength="255" show-word-limit />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="reset">
        关闭
      </el-button>
      <el-button type="primary" @click="present(4)">
        提交
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { stockTransAudit } from '@/api'

  export default {
    name: 'cancellation-cause',
    components: {
    },
    data() {
      return {
        visible: false,
        rejectRemark: '',
        temp: {}
      }
    },
    methods: {
      async open(row) {
        console.log('row', row)
        this.temp = JSON.parse(JSON.stringify(row))
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      // 提交
      async present(transStatus) {
        this.$set(this.temp, 'transStatus', transStatus)
        this.$set(this.temp, 'rejectRemark', this.rejectRemark)
        try {
          const { status } = await stockTransAudit(this.temp)
          if (status === 200) {
            this.$notify({
              title: '提示',
              message: '操作成功',
              type: 'success',
              duration: 2000
            })
            this.visible = false
            this.$emit('upDataCause')
          }
        } catch (error) {
          this.$set(this.temp, 'transStatus', 1)
        }
      },
      reset() {
        this.visible = false
        this.rejectRemark = ''
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
